<table class="table table-striped">
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>URL Pattern</th>
      <th>Method</th>
      <th>Domain</th>
      <th>Status</th>
      <th>UseDefault</th>
      <th>DefaultValue</th>
      <th>ClusterID</th>
      <th>MatchRule</th>
      <th>Position</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
    <% @apis.each do |api| %>
      <tr>
        <td><%= link_to api.id, api_path(api.id), class: 'btn btn-info btn-xs' %></td>
        <td><%= api.name %></td>
        <td><%= api.url_pattern %></td>
        <td><%= api.method %></td>
        <td><%= api.domain %></td>
        <td><%= api.status_name %></td>
        <td><%= api.use_default %></td>
        <td><%= api.default_value.try(:body).try(:force_encoding, "UTF-8") %></td>
        <% cluster_ids = (api.nodes || []).map{|node| node.cluster_id}.uniq %>
        <td>
          <% cluster_ids.each do |x| %>
            <%=raw link_to(x, cluster_path(x), class: 'btn btn-info btn-xs') %>
          <% end %>
        </td>
        <td><%= api.match_rule_name %></td>
        <td><%= api.position %></td>
        <td>
          <%= link_to '编辑', edit_api_path(api.id), class: 'btn btn-warning btn-xs' %>
          <%= link_to '删除', api_path(api.id), method: :delete, class: 'btn btn-danger btn-xs', data: {confirm: "你确认删除吗？"} %>
        </td>
      </tr>
    <% end %>
  <tbody>
</table>

<%= link_to '新建API', new_api_path, class: 'btn btn-primary' %>

<% last_id = @apis.max{|x| x.id}.try(:id).to_i %>
<%= link_to '第一页', apis_path(after: 0, per_page: @per_page || 10), class: 'btn btn-primary' %>
<%= link_to_if last_id, '下一页', apis_path(after: last_id, per_page: @per_page || 10), class: 'btn btn-primary' %>
